/**
 *  @file NoCopyAndNew.h
 */
#ifndef _NOCOPYANDNEW_H_
#define _NOCOPYANDNEW_H_

#include "commontypes.h"

namespace cppflib
{

/**
 *  For other classes to derive from so that they can't be copied implicitly and newed on heap 
 */
class _DLLAPI NoCopyAndNew
{
private:
   /* 
    *  Declare these to be private so that this object cannot be newed or copied implicitly
    */
   NoCopyAndNew(const NoCopyAndNew &) {  }
   const NoCopyAndNew& operator=(const NoCopyAndNew&) { return *this; }
   void *operator new(sz_t size) { throw "'new' isn't supported"; }   // return NULL will be complained by g++
   void operator delete(void *p) { }
   void *operator new[](sz_t size) { throw "'new' isn't supported"; } // return NULL will be complained by g++
   void operator delete[](void *p) { }

protected:
   NoCopyAndNew() { }
   ~NoCopyAndNew() { }
};

/**
 *  For classes which cannot be copied implicitly
 */
class _DLLAPI NoCopy
{
private:
   NoCopy(const NoCopy &) {  }
   const NoCopy& operator=(const NoCopy&) { return *this; }

protected:
   NoCopy() { }
   ~NoCopy() { }
};

}  // namespace cppflib

#endif
